//
//  AF_TypeCell.m
//  yigou
//
//  Created by wangdianlei on 2017/1/10.
//  Copyright © 2017年 hanyiwang. All rights reserved.
//

#import "AF_TypeCell.h"

#define buttonBackgroundColor [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1]

@implementation AF_TypeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.button1 = [[UIButton alloc]init];
    [self.button1 setBackgroundColor:buttonBackgroundColor];
    self.button1.titleLabel.font = [UIFont systemFontOfSize:14.0];
    self.button1.clipsToBounds = YES;
    self.button1.layer.cornerRadius = 5.0;
    [self.button1 setTitle:@"一口价" forState:UIControlStateNormal];
    [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.button1 setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
    [self.button1 addTarget:self action:@selector(buttonClick1:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button1];
    
    self.button2 = [[UIButton alloc]init];
    [self.button2 setBackgroundColor:buttonBackgroundColor];
    self.button2.titleLabel.font = [UIFont systemFontOfSize:14.0];
    self.button2.clipsToBounds = YES;
    self.button2.layer.cornerRadius = 5.0;
    [self.button2 setTitle:@"拍品" forState:UIControlStateNormal];
    [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.button2 setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
    [self.button2 addTarget:self action:@selector(buttonClick2:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button2];
    
    CGFloat spacing = 5.0;//行、列 间距
    int totalloc = 3;//列数
    CGFloat appvieww = (ScreenW - 100 - spacing*4)/totalloc;
    CGFloat appviewh = 30;
    
    NSInteger loc = 0, row = 0;
    CGFloat appviewx = spacing + (spacing + appvieww) * loc;
    CGFloat appviewy = spacing + (spacing + appviewh) * row;
    self.button1.frame = CGRectMake(appviewx, appviewy, appvieww, appviewh);
    
    loc = 1;
    appviewx = spacing + (spacing + appvieww) * loc;
    appviewy = spacing + (spacing + appviewh) * row;
    self.button2.frame = CGRectMake(appviewx, appviewy, appvieww, appviewh);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)buttonClick1:(UIButton *)button {
    if (!button.selected) {
        button.selected = YES;
        [button setBackgroundColor:[UIColor whiteColor]];
        button.layer.borderWidth = 0.5;
        button.layer.borderColor = [UIColor redColor].CGColor;
    } else {
        button.selected = NO;
        [button setBackgroundColor:buttonBackgroundColor];
        button.layer.borderWidth = 0.0;
    }
    self.button2.selected = NO;
    [self.button2 setBackgroundColor:buttonBackgroundColor];
    self.button2.layer.borderWidth = 0.0;
    [DataCenter sharedDataCenter].sxtype = @"0";
}

- (void)buttonClick2:(UIButton *)button {
    if (!button.selected) {
        button.selected = YES;
        [button setBackgroundColor:[UIColor whiteColor]];
        button.layer.borderWidth = 0.5;
        button.layer.borderColor = [UIColor redColor].CGColor;
    } else {
        button.selected = NO;
        [button setBackgroundColor:buttonBackgroundColor];
        button.layer.borderWidth = 0.0;
    }
    self.button1.selected = NO;
    [self.button1 setBackgroundColor:buttonBackgroundColor];
    self.button1.layer.borderWidth = 0.0;
    [DataCenter sharedDataCenter].sxtype = @"1";
}

@end
